package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.page.PageList;
import com.ruoyi.common.core.page.PageUtil;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.system.domain.TProdInvRecord;
import com.ruoyi.system.domain.dto.ITProdInvDTO;
import com.ruoyi.system.domain.vo.ITProdInvVO;
import com.ruoyi.system.domain.vo.TProdInvRecordVO;
import com.ruoyi.system.service.ITProdInvRecordService;
import com.ruoyi.system.service.ITProdInvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wux
 * @date 2023/5/31 16:08
 */
@Api(tags = "(客户端) 库存管理接口")
@RestController
@RequestMapping("/client/inv")
public class TProdInvController {
    @Autowired
    private ITProdInvService prodInvService;

    @Autowired
    private ITProdInvRecordService prodInvRecordService;

    @GetMapping("/list")
    @ApiOperation(value = "库存列表查询")
    public ResultEntity<PageList<ITProdInvVO>> listByPage(ITProdInvDTO params) {
        return ResultEntity.createSuccess(PageUtil.getPageList(prodInvService.listByPage(params)));
    }

    @GetMapping("/recordList")
    @ApiOperation(value = "商品出入库列表查询")
    public ResultEntity<PageList<TProdInvRecordVO>> recordList(ITProdInvDTO.ITProdInvRecordDTO params) {
        return ResultEntity.createSuccess(prodInvRecordService.listByPage(params));
    }

    @GetMapping("/recordById/{id}")
    @ApiOperation(value = "商品出入库查询（根据ID）")
    public ResultEntity<TProdInvRecordVO> recordById(@ApiParam(value = "库存记录ID", required = true) @PathVariable Long id) {
        ITProdInvDTO.ITProdInvRecordDTO params = new ITProdInvDTO.ITProdInvRecordDTO();
        params.setId(id);
        PageList<TProdInvRecordVO> tProdInvRecordVOPageList = prodInvRecordService.listByPage(params);
        List<TProdInvRecordVO> tProdInvRecordVOS = tProdInvRecordVOPageList.getData();
        TProdInvRecordVO tProdInvRecordVO = null;
        if (tProdInvRecordVOS.size() > 0) {
            tProdInvRecordVO = tProdInvRecordVOS.get(0);
        }
        return ResultEntity.createSuccess(tProdInvRecordVO);
    }

    @PostMapping("/out")
    @ApiOperation(value = "产品品出库")
    public ResultEntity outProd(@RequestBody ITProdInvDTO.ITProdInvOutDTO params) {
        prodInvRecordService.outProd(params);
        return ResultEntity.createSuccess();
    }

}
